package com.ddd.infrastructure.config;

import com.ddd.infrastructure.config.interceptor.InterceptorDemo1;
import com.ddd.infrastructure.config.interceptor.InterceptorDemo2;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
@Configuration
public class InterceptorConfiguration implements WebMvcConfigurer {

    /**
     * 注册自定义拦截器
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //  /**代表拦截所有请求  执行顺序和配置顺序有关系，即先配置顺序就在前
        //        添加拦截器

        new InterceptorDemo1();
        registry.addInterceptor(new  InterceptorDemo1() )
//                定义拦截路径
                .addPathPatterns("/**")
//                定义放行路径
                .excludePathPatterns("/index/**");
        //        添加拦截器
        registry.addInterceptor(new InterceptorDemo2())
//                定义拦截路径
                .addPathPatterns("/**")
//                定义放行路径
                .excludePathPatterns("/index/**");
    }
}
